﻿using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom;

namespace NRemedy
{
    public class GenerateClass
    {
        public void Create(CodeNamespace rootNamespace, string className , string formName)
        {
            //parameter check
            if (rootNamespace == null) throw new ArgumentNullException("rootNamespace");
            if (string.IsNullOrEmpty(className)) throw new ArgumentNullException("className");
            if (className.Contains(".")) throw new InvalidOperationException("className should not contains '.'");

            CodeTypeDeclaration classType = new CodeTypeDeclaration(className);
            classType.BaseTypes.Add(new CodeTypeReference("NRemedy.ARForm"));

            //define MemberAttributes
            classType.Attributes = MemberAttributes.Public;

            //add attribute
            GenerateClassAttribute attributeGenerator = new GenerateClassAttribute();
            Dictionary<string,object> _attributeProperties = new Dictionary<string,object>();
            _attributeProperties.Add("FormName",formName);
            attributeGenerator.Create(classType, typeof(ARFormMappingAttribute), _attributeProperties);

            rootNamespace.Types.Add(classType);
        }
    }
}
